package com.xingkeduo.tool;

/**
 * 统一返回结果
 */
public class BaseResultUtil {

    private String code;
    private String msg;
    private Object data;
    private int status;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public BaseResultUtil() {
    }

    public BaseResultUtil(Integer status, String data) {
        this.status = status;
        this.data = data;
    }

    public BaseResultUtil(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static BaseResultUtil success() {
        return success("操作成功!");
    }

    public static BaseResultUtil success(String data) {
        return new BaseResultUtil("0000", "success", data);
    }

    public static BaseResultUtil success(Object obj) {
        if(obj==null){
            return new BaseResultUtil("0000","success",null);
        }
        return new BaseResultUtil("0000","success", obj);
    }

    public static BaseResultUtil success(String msg, Object obj) {
        return new BaseResultUtil("0000", msg, obj);
    }

    public static BaseResultUtil failure(String msg) {
        return new BaseResultUtil("0001", msg, "null");
    }

    public static BaseResultUtil noDataEntity() {
        return new BaseResultUtil("0000", "查无记录!", "{}");
    }

    public static BaseResultUtil noDataList() {
        return new BaseResultUtil("0000", "查无记录!", "[]");
    }

    public void setErrorMsg(String msg,String data) {
        this.status=1;
        this.code = "0001";
        this.msg = msg;
        this.data = data;
    }
    public void setSuccMsg(String msg,String data) {
        this.status=0;
        this.code = "0000";
        this.msg = msg;
        this.data = data;
    }
}
